# coding:utf-8
import urllib2,cookielib

url = 'http://www.baidu.com'

# 创建cookie容器
cj = cookielib.CookieJar()

# 创建opener对象
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

# 给urllib2安装opener对象
urllib2.install_opener(opener)

# 打开网页
response = urllib2.urlopen(url)

print cj, '\n'
print response.read()